package org.jeecg.modules.monitoringindicators.app.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Queue;
import java.util.stream.Collectors;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.monitoringindicators.entity.FieldBlockLocation;
import org.jeecg.modules.monitoringindicators.service.IFieldBlockLocationService;

import lombok.extern.slf4j.Slf4j;

import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

/**
 * @Description: 田块位置参数表
 * @Author: Wenjl
 * @Date: 2022-01-25
 * @Version: V1.0
 */
@Api(tags = "App田块位置参数")
@RestController

@RequestMapping("/app/monitoringindicators/fieldBlockLocation")
@Slf4j
public class AppFieldBlockLocationController extends JeecgController<FieldBlockLocation, IFieldBlockLocationService> {
    @Autowired
    private IFieldBlockLocationService fieldBlockLocationService;

    /**
     * 列表查询
     *
     * @return
     */
    @RequiresPermissions({"fieldBlockLocation"})
    @AutoLog(value = "田块位置参数表-列表查询")
    @ApiOperation(value = "田块位置参数表-列表查询", notes = "田块位置参数表-列表查询")
    @GetMapping(value = "/list")
    public Result<?> queryPageList() {

        List<FieldBlockLocation> list = fieldBlockLocationService.list();
        return Result.OK(list);
    }

    /**
     * 添加
     *
     * @param fieldBlockLocation
     * @return
     */
    @AutoLog(value = "田块位置参数表-添加")
    @ApiOperation(value = "田块位置参数表-添加", notes = "田块位置参数表-添加")
    @PostMapping(value = "/add")
    public Result<?> add(@RequestBody FieldBlockLocation fieldBlockLocation) {
        fieldBlockLocationService.save(fieldBlockLocation);
        return Result.OK("添加成功！");
    }

    /**
     * 用来判断用户是否有权限访问添加页面
     *
     * @return
     */
    @RequiresPermissions({"fieldBlockLocation"})
    @AutoLog(value = "田块位置参数表-添加")
    @ApiOperation(value = "田块位置参数表-添加", notes = "田块位置参数表-添加")
    @PostMapping(value = "/toAdd")
    public Result<?> toAdd() {

        return Result.OK("true");
    }

    /**
     * 编辑
     *
     * @param fieldBlockLocation
     * @return
     */
    @AutoLog(value = "田块位置参数表-编辑")
    @ApiOperation(value = "田块位置参数表-编辑", notes = "田块位置参数表-编辑")
    @PutMapping(value = "/edit")
    public Result<?> edit(@RequestBody FieldBlockLocation fieldBlockLocation) {
        fieldBlockLocationService.updateById(fieldBlockLocation);
        return Result.OK("编辑成功!");
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "田块位置参数表-通过id删除")
    @ApiOperation(value = "田块位置参数表-通过id删除", notes = "田块位置参数表-通过id删除")
    @PostMapping(value = "/delete/{id}")
    public Result<?> delete(@PathVariable String id) {
        System.out.println(id);
        boolean b = fieldBlockLocationService.removeById(id);
        System.out.println(b);
        return Result.OK("删除成功!");
    }

    @AutoLog(value = "田块位置参数表-查找全部田块编号")
    @ApiOperation(value = "田块位置参数表-查找全部田块编号", notes = "田块位置参数表-查找全部田块编号")
    @GetMapping(value = "getFieldIdAll")
    public Result getFieldIdAll() {
        List<FieldBlockLocation> list = fieldBlockLocationService.list();
        List<String> collect = list.stream().map(p -> p.getFieldNumber()).collect(Collectors.toList());

        return Result.OK(collect);

    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "田块位置参数表-批量删除")
    @ApiOperation(value = "田块位置参数表-批量删除", notes = "田块位置参数表-批量删除")
    @DeleteMapping(value = "/deleteBatch")
    public Result<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        this.fieldBlockLocationService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功!");
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @AutoLog(value = "田块位置参数表-通过id查询")
    @ApiOperation(value = "田块位置参数表-通过id查询", notes = "田块位置参数表-通过id查询")
    @GetMapping(value = "/queryById/{id}")
    public Result<?> queryById(@PathVariable String id) {
        FieldBlockLocation fieldBlockLocation = fieldBlockLocationService.getById(id);
        if (fieldBlockLocation == null) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(fieldBlockLocation);
    }


}
